package fyf.com.carddesign.main.admin;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import fyf.com.carddesign.BaseActivity;
import fyf.com.carddesign.Bll.CardBll;
import fyf.com.carddesign.MyUtl.MyUtl;
import fyf.com.carddesign.MyUtl.Tuple.Tuple;
import fyf.com.carddesign.R;

/**
 * 添加卡片页面
 * Created by yxz on 2017/10/25.
 */

public class AddCardActivity extends BaseActivity {
    private AddCardActivity _parent;
    @BindView(R.id.tbb_tv_name)
    TextView _tvTitleName;

    @BindView(R.id.ac_et_title)
    EditText _etCardName;//卡片名字
    @BindView(R.id.ac_et_notice)
    EditText _etNotice;//备注信息
    @BindView(R.id.ac_et_num)
    EditText _etNum;//添加张数
    @BindView(R.id.ac_tv_date)
    TextView _tvDate;//添加日期

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        _parent = AddCardActivity.this;
        ButterKnife.bind(this);
        _tvTitleName.setText("添加挠痒卡");
        initSetContent();
    }

    //初始化数据
    private void initSetContent() {
        //
        // _etCardName.setText("测试测试测试");
    }

    /**
     * 按钮点击事件
     *
     * @param view
     */
    @OnClick(R.id.ac_btn_commit)
    public void onCommit(View view) {
        int num = 0;
        String cardName = _etCardName.getText().toString();
        String notice = _etNotice.getText().toString();
        String tmp = _etNum.getText().toString();//获取添加张数
        if (cardName.equals("")) {
            MyUtl.Toast(_parent, "卡片名称不能为空");
            return;
        }
        if (!tmp.equals("")) {
            num = Integer.valueOf(tmp);
        }
        /*----------不知道是不是异步！！！！！暂时不知道！！！待检查！--------*/
        Tuple<Boolean, String> tp = CardBll.getInstance(_parent).adminAddCard(cardName, notice, num);//添加卡片关键语句
        if (!tp.get_t1()) {//如果添加失败
            MyUtl.Toast(_parent, tp.get_t2());
            return;
        }
        MyUtl.Toast(_parent, tp.get_t2());
        _parent.finish();
    }

    @Override
    public int getLayoutId() {
        return R.layout.add_card;
    }

    @OnClick(R.id.tbb_ll_back)
    public void onBack(View v) {
        _parent.finish();
    }
}
